Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check __ANDROID_API__ instead of defining it automatically #633

Merged
merged 1 commit into from
May 15, 2018

Conversation

tomaka
Copy link
Contributor

@tomaka tomaka commented Mar 1, 2018

This pull requests removes the code that automatically defines the __ANDROID_API__ constant, and replaces it by a code that checks whether the constant has been defined by something else.
In other words, we now assume that the user manually defines __ANDROID_API__, for example through the CFLAGS environment variable.

The main reason is practical. If you generate a standalone NDK toolchain in order to compile your project, the wrapper automatically passes the __ANDROID_API__ constant to the actual compiler. Therefore if you try to compile ring for the standalone toolchain, you will most likely get a compilation error because the constant passed by the standalone conflicts with the one defined by ring.

I don't know how widely used ring for Android is, but I'm open to feedback about this change. I don't really have a very strong opinion ; my goal is mainly to make Android compilation as smooth as possible.

@tomaka
Copy link
Contributor Author

tomaka commented Mar 1, 2018

The current CI failure is not caused by this PR, however this PR may require changes in the CI configuration.

build.rs Outdated
required_api_level).unwrap();
if let Err(_) = cc::Build::new().warnings(false).file(tempfile.path()).try_expand() {
panic!("You need to define __ANDROID_API__ to at least {} for ring to compile",
required_api_level);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than generate a temporary file to test this, autoconf style, it seems better to just put the minimum version check #if logic in crypto/internal.h. Is there a reason you didn't do it that way?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did it this way for the nicer-looking user-friendlier error message, and also to consider defining the constant ourselves automatically if it is not provided by the user.
But I can do it in crypto/internal.h if you want.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I propose that we keep the code removal in your patch, but drop the code addition. Then, in the build documentation at https://github.com/briansmith/ring/blob/master/BUILDING.md, let's add a section on building for Android that indicates exactly what one must do to CFLAGS w.r.t. __ANDROID_API__ when building for Android.

In particular, IIUC, the Android SDK already does a check that __ANDROID_API__ is defined, so our check is somewhat superflous.

@coveralls
Copy link

coveralls commented Apr 13, 2018

Coverage Status

Coverage remained the same at ?% when pulling 9a0a708 on tomaka:android-api-check into 1caad72 on briansmith:master.

@coveralls
Copy link

Coverage Status

Coverage remained the same at ?% when pulling d194b81999deab3258e54522b4ae9794e81eb49b on tomaka:android-api-check into 1caad72 on briansmith:master.

Cargo.toml Outdated
@@ -290,6 +290,7 @@ lazy_static = "1.0"
# control about what should be parallised in which way
cc = "1.0.9"
rayon = "1.0.0"
tempfile = "2.2.0"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we're going to keep this, then this should be a conditional dependency only when the target OS is Android, if that is possible.

build.rs Outdated
required_api_level).unwrap();
if let Err(_) = cc::Build::new().warnings(false).file(tempfile.path()).try_expand() {
panic!("You need to define __ANDROID_API__ to at least {} for ring to compile",
required_api_level);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I propose that we keep the code removal in your patch, but drop the code addition. Then, in the build documentation at https://github.com/briansmith/ring/blob/master/BUILDING.md, let's add a section on building for Android that indicates exactly what one must do to CFLAGS w.r.t. __ANDROID_API__ when building for Android.

In particular, IIUC, the Android SDK already does a check that __ANDROID_API__ is defined, so our check is somewhat superflous.

@tomaka
Copy link
Contributor Author

tomaka commented Apr 18, 2018

Updated!

@@ -58,6 +58,9 @@ Note in particular that if you are cross-compiling an x86 build on a 64-bit
version of Linux, then you need to have the proper gcc-multilibs and
g++-multilibs packages or equivalent installed.

On Android, you will need to define the `__ANDROID_API__` constant to at least
`21` on 64-bit and `18` on 32-bit.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does this sound?:

If you generate a standalone NDK toolchain in order to compile your project, the wrapper automatically passes the ANDROID_API constant to the actual compiler. Otherwise, the __ANDROID_API__ must be defined with a value of at least 21 on 64-bit targets or 18 on 32-bit targets (e.g. export CFLAGS=-D__ANDROID_API__=21).

@briansmith briansmith merged commit f934a0b into briansmith:master May 15, 2018
@briansmith
Copy link
Owner

Thanks! Merged!

@briansmith
Copy link
Owner

I pushed df1ee11 to clarify the wording a bit like I suggested above.

@briansmith
Copy link
Owner

briansmith commented May 15, 2018

Reverted in b98f61f and b2fd4fa.

The Android build breaks in Travis CI; see https://travis-ci.org/briansmith/ring/jobs/379021311 for an example. I think the issue is that our Travis CI configuration is using GCC instead of clang; see https://github.com/android-ndk/ndk/wiki/Changelog-r14-beta1#wont-fix where it says standalone toolchains using GCC need to set define this macro manually. Probably we should switch to clang on Travis CI for all Android targets.

@tomaka
Copy link
Contributor Author

tomaka commented May 15, 2018

standalone toolchains using GCC need to set define this macro manually.

This should be done through the environment variables of cc-rs in my opinion.

@pietro
Copy link
Contributor

pietro commented May 15, 2018

Unfortunately I really haven't had time to deal with this. When I tried using clang the tests would fail. @tomaka can you build and test ring using clang for android?

@briansmith
Copy link
Owner

I think ring should just drop support for GCC in favor of requiring Clang for targeting Android. In I originally accepted this PR because I was assured that the __ANDROID_API__ stuff would happen automatically in the common case, but that automation seems to only be available for clang.

When I tried using clang the tests would fail.

If somebody writes a PR that gets us up to the point of failing tests (NOTE: As of now, all testing on Android is disabled on Travis CI) then I will investigate the test failures myself.

Then we can reland this.

@tomaka tomaka deleted the android-api-check branch May 16, 2018 09:11
@briansmith
Copy link
Owner

https://travis-ci.org/briansmith/ring/builds/382297181 is branch that attempts to reland this.

@briansmith
Copy link
Owner

briansmith commented May 22, 2018

Relanded as d8ec880 and 08ec4f3. Thanks!

@tomaka
Copy link
Contributor Author

tomaka commented May 23, 2018

Cool, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants